package com.kzw.oa.system.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kzw.core.bean.Msg;
import com.kzw.core.orm.Page;
import com.kzw.core.orm.PageRequest;
import com.kzw.core.orm.StringPropertyFilter;
import com.kzw.core.util.ExtjsUtil;
import com.kzw.core.util.json.JSON;
import com.kzw.core.util.web.ResponseUtils;
import com.kzw.oa.system.model.SystemLog;
import com.kzw.oa.system.service.SystemLogService;

@Controller
@RequestMapping("/system/systemLog")
public class SystemLogAction {
	
	@Autowired
	private SystemLogService systemLogService;

	/**
	 * 显示列表
	 */
	@RequestMapping("list")
	public void list(HttpServletRequest request, HttpServletResponse response){
		
		PageRequest pageRequest = ExtjsUtil.getPageReq(request);
		List<StringPropertyFilter> filters = ExtjsUtil.getFilters(request);
		Page<SystemLog> page = systemLogService.search2(pageRequest, filters);
		
		String json = new JSON(page, "yyyy-MM-dd HH:mm").buildWithFilters(3);
		ResponseUtils.renderJson(response, json);
	}
	
	/**
	 * 批量删除
	 */
	@RequestMapping("multiDel")
	@ResponseBody
	public Msg multiDel(String[] ids){
		if (ids != null) {
			systemLogService.remove(ids);
		}
		return new Msg(true);
	}
	
	/**
	 * 显示详细信息
	 */
	@RequestMapping("get")
	public void get(Long logId, HttpServletResponse response){
		SystemLog systemLog=systemLogService.get(logId);
		String json = new JSON(systemLog).buildWithFilters(3);
		ResponseUtils.renderJson(response, json);
	}
	
	/**
	 * 添加及保存操作
	 */
	@RequestMapping("save")
	@ResponseBody
	public Msg save(SystemLog systemLog){
		systemLogService.saveOrUpdate(systemLog);
		return new Msg(true);
	}
}
